package lesson10;

public class Test04 {
    public static void main(String[] args) {
        String s1 = "hello java,i love java";
        String s2 = "hello";
        String s3 = new String("hello");

        System.out.println(s1 == s2);
        System.out.println(s1 == s3);
        System.out.println(s1.equals(s3));

        // 获取字符串长度
        System.out.println(s1.length());
        for(int i = 0;i < s1.length();i++){
            System.out.println(s1.charAt(i));
        }

        // 根据指定的字符串进行搜索，返回对应的下标
        System.out.println(s1.indexOf("l"));
        System.out.println(s1.lastIndexOf("l"));

        // 截取字符串
        System.out.println(s1.substring(6));
        System.out.println(s1.substring(6,10));

        // 给定一个字符串："jsdaslasjfigas;dadhigas;dfjgas;sdljfoiajsdf;"，请输出这个字符串中一共有多少个as
        String str = "jsdaslasjfigas;dadhigas;dfjgas;sdljfoiajsdf;as";
//        int count = 0;
//        while(true){
//            int index = str.indexOf("as");
//            if(index >= 0){
//                count++;
//                str = str.substring(index + 2);
//            }else{
//                break;
//            }
//        }
//        System.out.println(count);

        String str1 = "aaa;bbb;ccc;ddd";
        // 字符串分割
        String [] ss = str1.split(";");
        System.out.println(ss.length);
        System.out.println(str.split("as").length);
        // 判断是否为指定字符串开头
        System.out.println(str.startsWith("js"));
        // 判断是否为指定字符串结尾
        System.out.println(str.endsWith("as"));

        String str2 = "hello" + " java" + " i" + " love" + " java";

        System.out.println(str2);

        // 可变字符串
        StringBuffer stringBuffer = new StringBuffer();
        StringBuilder stringBuilder = new StringBuilder();

        stringBuffer.append("hello");
        stringBuffer.append(" java");
        stringBuffer.append(" i");
        stringBuffer.append(" love");
        stringBuffer.append(" java");
        System.out.println(stringBuffer);

        StringBuffer stringBuffer1 = stringBuffer.reverse();
        System.out.println(stringBuffer == stringBuffer1);
    }
}
